home *** CD-ROM | disk | FTP | other *** search
Text File | 1988-07-28 | 2.1 KB | 97 lines | [TEXT/MPS ] |
- ### NewTempFile — Open a window on a new temporary file.
- ### W. Powell, 1988
- ### Automatically insures unique file names.
-
- Set Exit 0
- Set TargMode 0
- Set EchoMode 0
- Unset BaseName
- Set NameIn 0
- Set ErrGen 0
- # Check calling arguments
- If {#} > 3
- Echo "### NewTempFile — bad arguments" >>Dev:StdErr
- Echo "### NewTempFile [-t] [-e | -q] [basename] " >>Dev:StdErr
- Exit 1
- End
- # Use the arguments
- If {#} > 0
- For NewArg In {"Parameters"}
- If "{NewArg}" == "-t"
- Set TargMode 1
- Else If "{NewArg}" == "-e"
- If {EchoMode}
- Echo "### NewTempFile - only one of -e, -q allowed" >>Dev:StdErr
- Echo "### NewTempFile [-t] [-e | -q] [basename] " >>Dev:StdErr
- Exit 1
- Else
- Set EchoMode 1
- Set Quote 0
- End
- Else If "{NewArg}" == "-q"
- If {EchoMode}
- Echo "### NewTempFile - only one of -e, -q allowed" >>Dev:StdErr
- Echo "### NewTempFile [-t] [-e | -q] [basename] " >>Dev:StdErr
- Exit 1
- Else
- Set EchoMode 1
- Set Quote 1
- End
- Else
- If {NameIn}
- Echo "### NewTempFile — bad arguments" >>Dev:StdErr
- Echo "### NewTempFile [-t] [-e | -q] [basename] " >>Dev:StdErr
- Exit 1
- Else
- Set NameIn 1
- Set BaseName "{NewArg}"
- End
- End
- End
- End
- # If basename not specified, use this default
- If ¬ {NameIn}
- Set BaseName TEMPzs
- End
- Unset NameIn
-
- # Note: Directory for temp files defined by variable
- # {TMP} defined in Startup script
- Set TmpCnt `Files "{TMP}" | Count -l`
- Set TmpCnt `Evaluate {TmpCnt} + 1 `
-
- # Create a unique new Temporary File
- Loop # Until unique new file is opened
- # Trial filename
- Set uniq "{TMP}{BaseName}{TmpCnt}"
- # Try to create file
- If "{uniq}" == `Exists -f "{uniq}" `
- # Not a unique name, so
- # Increment and try again
- Set TmpCnt `Evaluate {TmpCnt} + 1 `
- Else
- # Found a good file name, try to open it.
- New "{uniq}"
- Set NewStat {Status}
- If {NewStat}
- Echo "### NewTempFile terminated" ≥≥Dev:StdErr
- Exit {NewStat}
- End
- If {TargMode}
- Open -t "{uniq}"
- End
- If {EchoMode}
- If {Quote}
- Quote "{uniq}"
- Else
- Echo "{uniq}"
- End
- End
- Break # out of this loop
- End
- End
- # Successful, Window is open
- Exit 0
-
- ### End file NewTempFile
- ##############################